package com.tang.portal.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tang.framework.core.controller.BaseController;
import com.tang.framework.core.domain.HttpResult;

import com.tang.common.model.req.ReqId;
import com.tang.common.model.req.ReqIds;
import com.tang.service.account.model.req.ReqBaseUser;
import com.tang.service.account.model.req.ReqBaseUserAdd;
import com.tang.service.account.model.res.ResBaseUser;
import com.tang.service.account.model.res.ResBaseUserDetail;
import com.tang.portal.facade.BaseUserFacade;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import jakarta.annotation.Resource;
import java.io.IOException;

/**
 * @author tang jun liang
 * @Date 2023-4-3 09:04:00
 */
@RestController
@RequestMapping("/Tag/base/user")
@Tag(name = "基本用户")
public class BaseUserController extends BaseController {

    @Resource
    private BaseUserFacade baseUserFacade;


    @Operation(summary = "删除基本用户表")
    @PostMapping("/delete")
    public HttpResult<String> remove(@RequestBody ReqId id) {
        return baseUserFacade.remove(id, getCurrLoginUser());
    }

    @Operation(summary = "基本用户表详情")
    @PostMapping("/detail")
    public HttpResult<ResBaseUserDetail> detail(@RequestBody ReqId id) {
        return baseUserFacade.detail(id, getCurrLoginUser());
    }

    @Operation(summary = "基本用户表详情")
    @PostMapping("/list")
    public HttpResult<IPage<ResBaseUser>> list(@RequestBody ReqBaseUser reqBaseUser) {
        return baseUserFacade.list(reqBaseUser, getCurrLoginUser());
    }


    @Operation(summary = "新增基本用户表")
    @PostMapping("/add")
    public HttpResult<String> add(@RequestBody ReqBaseUserAdd baseUserAdd) {
        return baseUserFacade.add(baseUserAdd);
    }

    @Operation(summary = "编辑基本用户表")
    @PostMapping("/edit")
    public HttpResult<String> update(@RequestBody ReqBaseUserAdd baseUserAdd) {
        return baseUserFacade.update(baseUserAdd);
    }


    @Operation(summary = "导出excel-基本用户表")
    @PostMapping("/export")
    public void export(@RequestBody ReqIds ids) {
        baseUserFacade.export(ids, httpServletResponse);
    }

    @Operation(summary = "导出excel-模版")
    @PostMapping("/exportTemplate")
    public void exportTemplate() {
        baseUserFacade.exportTemplate(httpServletResponse);
    }


    @Operation(summary = "导入excel-基本用户表")
    @PostMapping("/importExcel")
    public HttpResult<String> importExcel(MultipartFile file) throws IOException {
        return baseUserFacade.importExcel(file);
    }


}
